package com.bookstore.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

@WebServlet(name = "BaseServlet", value = "/BaseServlet")
public class BaseServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Content-Type","test/html;charset=utf-8");
        String method = request.getParameter("action");
        try {
            Class<? extends BaseServlet> clazz=this.getClass();
            Method clazzMethod = clazz.getDeclaredMethod(method, HttpServletRequest.class, HttpServletResponse.class);
            clazzMethod.setAccessible(true);
            clazzMethod.invoke(this,request,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
